#include "ShooterObject.h"
#include "TextureManager.h"
#include "Game.h"

ShooterObject::ShooterObject ():
    GameObject(),m_position(0,0),
    m_velocity(0,0), m_acceleration(0, 0)
{    
    m_currentRow = 1;
    m_currentFrame = 1;
}

void ShooterObject::load(std::unique_cast<LoaderParams> const & pParams){
    m_position = Vector2D(pParams->getX(), pParams->getY());
    m_velocity = Vector2D(0, 0);
    m_acceleration = Vector2D(0, 0);
    m_width = pParams->getWidth();
    m_height = pParams->getHeight();
    m_textureID = pParams->getTextureID();
    m_currentRow = 1;
    m_currentFrame = 1;
    m_numFrames = pParams->getNumFrames();
}

void ShooterObject::draw(){
    if (m_velocity.getX() >0){
            TextureManager::Instance()->drawFrame(m_textureID,
                                                (int)m_position.getX(), 
                                                (int)m_position.getY(),
                                                m_width, m_height,
                                                m_currentRow,
                                                m_currentFrame,
                                                TheGame::Instance()->getRenderer(),                                                     SDL_FLIP_HORIZONTAL
                                                );

    }
    else
    {
        TextureManager::Instance()->drawFrame(m_textureID,
                                                (int)m_position.getX(), 
                                                (int)m_position.getY(),
                                                m_width, m_height,
                                                m_currentRow,
                                                m_currentFrame,
                                                TheGame::Instance()->getRenderer());
    }
}

void ShooterObject::update() {
    m_velocity += m_acceleration;
    m_position += m_velocity;
}

void ShooterObject::clean() {}

void ShooterObject::doDyingAnimation() 
{
    scroll(TheGame::Instance()->getScrollSpped());

    m_currentFrame = int((SDL_GetTicks()/(1000/3)) % m_numFrames);
    
    if (m_dyingCounter == m_dYingTime){
        m_bDead = true;
    }
    m_dyingCounter++;
}
































